<?php
/**
 * Created by .
 * User: luogan
 * Date: 2022/1/13
 */

namespace app\model;

use think\model\concern\SoftDelete;
use hg\apidoc\annotation\Field;
use hg\apidoc\annotation\AddField;
use hg\apidoc\annotation\Param;

class AdminModel extends BaseModel
{
    use SoftDelete;
    protected $table = 'api_admin';
    protected $pk = 'id';
    protected $autoWriteTimestamp=true;
    protected $deleteTime = 'delete_time';
    protected $hidden=['delete_time','password','salt'];

    /**
     * 获取修改最后一次登录时间
     * @param $value
     * @param $data
     * @return false|string
     */
    public function getLastLoginTimeAttr($value,$data)
    {
        $value = date('Y-m-d H:i:s',$value);
        return $value;
    }

    /**
     * 搜索昵称
     * @param $query
     * @param $value
     */
    public function searchNicknameAttr($query, $value, $data)
    {
        if ($value){
            $query->where('nickname','like', '%'. $value . '%');
        }

    }

    /**
     * 搜索手机号
     * @param $query
     * @param $value
     */
    public function searchMobileAttr($query, $value, $data)
    {
        if ($value){
            $query->where('mobile','like', '%'. $value . '%');
        }

    }

    /**
     * 搜索邮箱
     * @param $query
     * @param $value
     */
    public function searchEmailAttr($query, $value, $data)
    {
        if ($value){
            $query->where('email','like', '%'. $value . '%');
        }

    }

    /**
     * 搜索状态
     * @param $query
     * @param $value
     */
    public function searchStatusAttr($query, $value, $data)
    {
        if ($value){
            $query->where('status',$value);
        }

    }


    /**
     * 搜索创建时间
     * @param $query
     * @param $value
     */
    public function searchCreateTimeAttr($query, $value, $data)
    {
        if ($value){
            $query->whereBetweenTime('create_time', $value[0], $value[1]);
        }
    }

    /**
     * 获取管理员
     * @Field("id,nickname,username,head_pic,email,sex,role,dept_id,last_login_time,last_login_ip,status,create_time,update_time")
     */
    public function getAdmin(){}

    /**
     * 获取管理员列表
     * @Field("id,nickname,username,head_pic,email,sex,role,dept_id,last_login_time,last_login_ip,status,create_time,update_time")
     * @AddField("role",type="array",desc="重写role字段",
     *     @Param ("id",type="string",desc="id"),
     *     @Param ("name",type="string",desc="名称"),
     * )
     */
    public function getList($data){}


}
